package test;

public class RockPaperScissors {
	
	
	Result play(RPSEnum p1, RPSEnum p2)
	{
		switch(p1){
		case PAPER:
			switch(p2){
			case PAPER:
				return Result.TIE;
			case ROCK:
				return Result.WIN;
			case SCISSORS:
				return Result.LOST;
			}
		case ROCK:
			switch(p2){
			case ROCK:
				return Result.TIE;
			case SCISSORS:
				return Result.WIN;
			case PAPER:
				return Result.LOST;
			}
		case SCISSORS:
			switch(p2){
			case SCISSORS:
				return Result.TIE;
			case PAPER:
				return Result.WIN;
			case ROCK:
				return Result.LOST;
			}
		default:
			return Result.LOST;
			
		}
	}
	
	Result play(Player p1, Player p2)
	{
		int scoreP1, scoreP2;
		scoreP1 = 0;
		scoreP2 = 0;
		for (int i=0; i < p1.getNumberOfMoves(); i++)
		{
			Result res = play(p1.getNextMove(i), p2.getNextMove(i));
			if (res == Result.LOST)
				scoreP2++;
			else if (res == Result.WIN)
				scoreP1++;
			else if (res == Result.TIE){
				scoreP1++;
				scoreP2++;
			}
		}
		p1.setScore(scoreP1);
		p2.setScore(scoreP2);
		if(p1.getScore() > p2.getScore())
		{
			//System.out.println("WIN");
			return Result.WIN;
		}
		else if(p1.getScore() < p2.getScore())
		{
			//System.out.println("LOST");
			return Result.LOST;
		}
		else
		{
			//System.out.println("TIE");
			//System.out.println(scoreP1 +" "+ scoreP2);
			return Result.TIE;
		}
	}
}
